import {
  setItem,
  getItem
} from '@/utils/storage'

const addressKey = 'ADDRESS'
const DaddressKey = 'D-ADDRESS'

const state = {
  address: getItem(addressKey) || [],
  defaultAddress: getItem(DaddressKey) || {},
  active: 0
}

const mutations = {

  // 默认地址
  setDefaultAddress(state, address) {
    state.defaultAddress = address
    setItem(DaddressKey, state.defaultAddress)
  },
  removeDefaultAddress(state) {
    state.defaultAddress = {}
    setItem(DaddressKey, '')
  },
  updateActive(state, value) {
    state.active = value
  }
}

export default {
  namespaced: true,
  state,
  mutations
}
